<template>
  <div id="newSurveyMap-map" style="width:100%;height:754px;"></div>
  <!-- width可以为100%，但是height必须是一个确定的值 -->
  <div id="newSurveyMap-mapDiv" class="ol-popup">
    <!-- 显示控件 -->
    <div id="newSurveyMap-setDivPosition"  class="init-setDivPosition">
      <!-- 切换卫星和街道地图 -->
      <p @click="switchMap" class="init-setDivPosition-selected">
        <template v-if="switchMapBool==false">
          <img src="@/assets/map/image/weixing-b.png" title="切换卫星地图"><br/><span>卫星图</span>
        </template>
        <template v-else>
          <img src="@/assets/map/image/jiedao-b.png" title="切换街道地图"><br/><span>街道图</span>
        </template>
      </p>
      <!-- 返回主界面 -->
      <p @click="zoomDefaultPosition" :class="{ 'init-setDivPosition-selected': zoomDefaultPositionBool==true }">
        <img src="@/assets/map/image/newImage/home.png" title="返回主界面"><br/><span>主界面</span>
      </p>
      <!-- 显示工具箱 -->
      <p @click="showHideToolsBoxDiv" :class="{ 'init-setDivPosition-selected': showHideToolsBox==false }">
        <template v-if="showHideToolsBox">
          <img src="@/assets/map/image/tools.png" title="打开工具箱"><br/><span>工具箱</span>
        </template>
        <template v-else>
          <img src="@/assets/map/image/tools.png" title="关闭工具箱"><br/><span>工具箱</span>
        </template>
      </p>
      <!-- 任务接口 -->
      <p @click="mapDrawSurveyPoint" :class="{ 'init-setDivPosition-selected': showHideNewSurveyBool==false }">
        <img id="newSurveyMap-setTaskDiv-img" title="新建调研点" src="@/assets/map/image/hf_rxdw_r.png"><br/>
        <span id="newSurveyMap-setTaskDiv-span" style="font-size:12px;">新建调研点</span>
      </p>
      <!-- 是否显示房屋抗震能力分区图层 -->
      <p @click="showHideFwLayer" style="height: 105px;" :class="{ 'init-setDivPosition-selected': showHideFwLayerBool==false }">
        <template v-if="showHideFwLayerBool">
          <img src="@/assets/map/image/fwdisplay.png" title="显示房屋抗震能力分区图层"><br/><span style="border:0;line-height: 20px;">显示房屋抗震能力分区图层</span>
        </template>
        <template v-else>
          <img src="@/assets/map/image/fwhide.png" title="隐藏房屋抗震能力分区图层"><br/><span style="border:0;line-height: 20px;">隐藏房屋抗震能力分区图层</span>
        </template>
    </p>
    </div>
    <!-- 工具箱 -->
    <div id="newSurveyMap-ToolsBoxDiv" class="init-ToolsBoxDiv">
      <p @click="measureToolBox" :class="{ 'init-setDivPosition-selected': showHideMeasureTool==false }">
        <template v-if="showHideMeasureTool">
          <img title="开启测量工具" src="@/assets/map/image/cel.png"><br/><span>测量</span>
        </template>
        <template v-else>
          <img title="关闭测量工具" src="@/assets/map/image/cel.png"><br/><span>测量</span>
        </template>
      </p>
      <p @click="positionToolBox" :class="{ 'init-setDivPosition-selected': showHidePositionTool==false }">
        <template v-if="showHidePositionTool">
          <img title="开启定位工具" src="@/assets/map/image/dingw.png"><br/><span style="border:0;">定位</span>
        </template>
        <template v-else>
          <img title="关闭定位工具" src="@/assets/map/image/dingw.png"><br/><span style="border:0;">定位</span>
        </template>
      </p>
    </div>
    <!-- 所有工具 -->
    <div id="newSurveyMap-AllToolsDiv" class="init-AllToolsDiv">
      <!-- 测量工具 -->
      <div id="newSurveyMap-MeasureToolsDiv" class="init-AllToolsDivFloat">
        <p @click="measureDistance" :class="{ 'init-setDivPosition-selected': measureDistanceBool==false }">
          <template v-if="measureDistanceBool">
            <img src="@/assets/map/image/jul.png" title="测量距离（在地图上单击鼠标左键绘制折线，双击完成测量）"><br/><span>测量距离</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/jul.png" title="测量距离（在地图上单击鼠标左键绘制折线，双击完成测量）"><br/><span>测量距离</span>
          </template>
        </p>
        <p class="init-AllToolsDiv-split"></p>
        <p @click="measureArea" :class="{ 'init-setDivPosition-selected': measureAreaBool==false }">
          <template v-if="measureAreaBool">
            <img src="@/assets/map/image/mianj.png" title="测量面积（在地图上单击鼠标左键绘制多边形，双击完成测量）"><br/><span>测量面积</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/mianj.png" title="测量面积（在地图上单击鼠标左键绘制多边形，双击完成测量）"><br/><span>测量面积</span>
          </template>
        </p>
        <p class="init-AllToolsDiv-split"></p>
        <p @click="stopMeasure" :class="{ 'init-setDivPosition-selected': stopMeasureBool==false }">
          <template v-if="stopMeasureBool">
            <img src="@/assets/map/image/jshz.png" title="取消测量距离或测量面积操作"><br/><span>结束测量</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/jshz.png" title="取消测量距离或测量面积操作"><br/><span>结束测量</span>
          </template>
        </p>
        <p class="init-AllToolsDiv-split"></p>
        <p @click="clearMeasure" :class="{ 'init-setDivPosition-selected': clearMeasureBool==false }">
          <template v-if="clearMeasureBool">
            <img src="@/assets/map/image/qux.png" title="清空全部测量结果"><br/><span>清空结果</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/qux.png" title="清空全部测量结果"><br/><span>清空结果</span>
          </template>
        </p>
      </div>
      <!-- 定位工具 -->
      <div id="newSurveyMap-MousePositionDiv">
        <span><img class="init-jingd" src="@/assets/map/image/jingd.png" title="鼠标左键在地图上点击位置的经度值"></span>
        <input id="newSurveyMap-MousePositionLon" type="text" value="">
        <span><img class="init-weid" src="@/assets/map/image/weid.png" title="鼠标左键在地图上点击位置的纬度值"></span>
        <input id="newSurveyMap-MousePositionLat" type="text" value="">
        <p @click="clearPosition" :class="{ 'init-setDivPosition-selected': clearPositionBool==false }">
          <template v-if="clearPositionBool">
            <img src="@/assets/map/image/qux.png" title="清空全部定位点图标"><br/><span>清空结果</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/qux.png" title="清空全部定位点图标"><br/><span>清空结果</span>
          </template>
        </p>
        <p class="init-AllToolsDiv-split"></p>
        <p @click="addPosition" :class="{ 'init-setDivPosition-selected': addPositionBool==false }">
          <template v-if="addPositionBool">
            <img src="@/assets/map/image/dingwd.png" title="根据经纬度值在地图上添加定位点图标"><br/><span>添加定位点</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/dingwd.png" title="根据经纬度值在地图上添加定位点图标"><br/><span>添加定位点</span>
          </template>
        </p>
      </div>
    </div>
    <!-- 弹出窗口 -->
    <!--<div id="newSurveyMap-popup" class="new-ol-popup">
      <a href="#" id="newSurveyMap-popup-closer" class="new-ol-popup-closer"></a>
      <div id="newSurveyMap-popup-content"></div>
    </div>-->
    <!-- 右键菜单 -->
    <div id="newSurveyMap-contextMenuDiv" class="init-contextMenuDiv">
      <div id="newSurveyMap-leftContextMenuDiv">
        <ul>
          <li id="newSurveyMap-newSurveyContextMenuLi" @click="newSurveyData">
            <span><img style='width:1px;' src=''>&nbsp;新建调研点&nbsp;&nbsp;</span>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>
<script>
import '@/assets/map/ol/ol.css';
import { getProjection,getResolutions,getTiandituVecMap,getTiandituVecText,getTiandituImgMap,getTiandituImgText,
  getRESTLayer,getVectorTileLayer,iServerHttp } from "@/map/projMap.js";
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import VectorLayer from 'ol/layer/Vector';
import {Cluster, Vector as VectorSource, XYZ} from 'ol/source'
import {Control, defaults as defaultControls} from 'ol/control';
import Overlay from 'ol/Overlay';
import Feature from 'ol/Feature';
import Point from 'ol/geom/Point';
import Polygon from 'ol/geom/Polygon';
import LineString from 'ol/geom/LineString';
import {Fill, Stroke, Style, Icon, Circle,Text} from 'ol/style';
import {Select, Draw, Modify, Snap, Translate} from 'ol/interaction';
import {getArea, getLength} from 'ol/sphere';
import {unByKey} from 'ol/Observable';
import GeoJSON from 'ol/format/GeoJSON';
import {boundingExtent} from 'ol/extent';
import { TileSuperMapRest,Logo,QueryByGeometryParameters,QueryService,AddressMatchService,GeoDecodingParameter } from '@supermap/iclient-ol';
import dingweiImg from '@/assets/map/image/newImage/blueMarker.png';
import dingweiTempImg from '@/assets/map/image/dingwd-r.png';

export default {
  name: "NewSurveyMap",
  components: {

  },
  props:{
    taskDistrict: {//任务行政区域
      type:String,
      required:true,
      default:""
    },
    taskRegion: {//任务区域经纬度
      type:String,
      required:true,
      default:""
    },
    isSaveMapPoint: {//是否保存调研点
      type:Boolean,
      required:true,
      default:false
    },
    taskSurveyList: {//任务ID对应的调研点列表
      type:Array,
      required:true,
      default:[]
    }
  },
  emits:["newSurveyData","mapLoading"],
  data() {
    return {
      str: "newSurveyMap",
      map: null,
      projection4490:null,
      center: [105, 34],
      zoom: 4,
      zoomDefaultPositionBool:true,//显示主界面
      switchMapBool:false,//切换地图
      layer1:null,//天地图街道图
      layer2:null,
      layer3:null,//天地图卫星图
      layer4:null,
      draw:null,//矢量绘制
      snap:null,
      select:null,
      modify:null,
      drag:null,
      source:null,//矢量绘制图层数据
      measureSource:null,//测量结果图层数据
      measure:null,//测量工具
      sketch:null,
      helpTooltipElement:null,
      helpTooltip:null,
      measureTooltipElement:null,
      measureTooltip:null,
      measureTooltipArray:[],//全部测量结果Overlay数组
      showHideMeasureTool:true,//显示|隐藏测量工具
      measureDistanceBool:true,
      measureAreaBool:true,
      stopMeasureBool:true,
      clearMeasureBool:true,
      showHidePositionTool:true,//显示|隐藏定位工具
      addPositionBool:true,
      clearPositionBool:true,
      popupInfoLayer:null,//弹出窗口
      newContextMenu:null,//新建调研点右键菜单
      showHideToolsBox:true,
      taskVectorLayer:null,//任务列表区域图层
      //新建调研点地图传参
      surveyAddressData:null,
      addressMatchService:null,//地址匹配
      addressUrl:"https://iserver.supermap.io/iserver/services/addressmatch-Address/restjsr/v1/address",
      taskDistrictData: null,//任务行政区域数据
      taskRegionData: null,//任务区域经纬度数据
      fwVectorLayer:null,//房屋抗震能力分区图层
      showHideFwLayerBool:true,//房屋抗震能力分区图层显示隐藏参数
      selectFeature:null,//选中要素
      fwLayerTypeList:['估计抗震能力达标', '疑似抗震能力不足', '疑似抗震能力严重不足'],//房屋抗震能力分区级别
      fwLayerColorList:['green', 'orange', 'red'],//房屋抗震能力分区级别颜色
      surveyVectorLayer:null,//全部调研点图层
      allDataList:[],//任务ID对应的全部调研点数据列表
      showHideNewSurveyBool:true//是否开启新建调研点
    }
  },
  watch: {
    taskDistrict: {//任务行政区域
      handler: function(newVal,oldVal){
        //if(newVal!=oldVal && newVal!=null && newVal!=""){
          this.taskDistrictData = newVal;
          console.log(newVal);
        //}
      },
      immediate:true
    },
    taskRegion: {//任务区域经纬度
      handler: function(newVal,oldVal){
        //if(newVal!=oldVal && newVal!=null && newVal!=""){
          this.taskRegionData = newVal;
          this.drawTaskPolygon();//绘制任务区域
        //}
      },
      immediate:true
    },
    isSaveMapPoint: {//是否保存调研点
      handler: function(newVal,oldVal){
        if(newVal){
          //移除选中要素
          this.source.removeFeature(this.selectFeature);
        }
      },
      immediate:true
    },
    taskSurveyList:{//任务ID对应的调研点列表
      handler: function(newVal,oldVal){
        this.allDataList = newVal;
        this.showAllDataList();
      },
      immediate:true
    }
  },
  created() {

  },
  mounted() {
    console.log("mounted");
    let that = this;
    //地图异步加载
    this.$nextTick(function(){
      console.log('地图异步加载');
      //地图异步加载
      setTimeout(() => {
        //初始化地图信息
        that.initMap();
        //绘制任务区域
        that.drawTaskPolygon();
        //显示调研点数据
        that.showAllDataList();
      }, 200);
    });
  },
  beforeCreate() {//生命周期创建之前
    console.log("beforeCreate");
  },
  beforeMount() {//生命周期挂载之前
    console.log("beforeMount");
  },
  beforeUpdate() {//生命周期更新之前
    console.log("beforeUpdate");
  },
  updated() {//生命周期更新之后
    console.log("updated");
  },
  beforeDestroy() {//生命周期销毁之前
    console.log("beforeDestroy");
  },
  destroyed() {//生命周期销毁完成
    this.map = null;
    console.log("销毁地图");
  },
  activated() {//如果页面有keep-alive缓存功能激活，这个函数会触发
    console.log("activated-"+this.str);
    //自动获取地图div高度
    this.autodivheight();
    //浏览器窗口发生变化时同时变化DIV高度
    window.onresize=this.autodivheight;
  },
  deactivated() {//如果页面有keep-alive缓存功能停用，这个函数会触发
    console.log("deactivated-"+this.str);
    //取消浏览器窗口发生变化时同时变化DIV高度事件
    window.onresize = null;
  },
  methods: {
    initMap() {
      debugger;
      let that = this;
      let mapStr = this.str;
      let targetMap = document.getElementById(mapStr+"-map");
      if(targetMap.innerHTML!=""){
        console.log("清空targetMap");
      }
      targetMap.innerHTML = "";//清空
      //新建popup弹窗
      let targetDiv = document.getElementById(mapStr+"-mapDiv");
      let node = document.createElement("div");
      node.id = mapStr+"-popup";
      node.setAttribute("class","new-ol-popup");
      node.innerHTML = '<a href="#" id="'+mapStr+'-popup-closer" class="new-ol-popup-closer"></a>' +
          '<div id="'+mapStr+'-popup-content"></div>';
      targetDiv.appendChild(node);
      console.log("新建popup");
      //自动获取地图div高度
      this.autodivheight();
      //浏览器窗口发生变化时同时变化DIV高度
      window.onresize=this.autodivheight;
      if(this.map){//避免重复加载地图
        console.log("避免重复加载地图");
        return;
      }
      console.log("初始化地图");
      //获取投影4490坐标系
      this.projection4490 = getProjection();
      //初始化地图信息
      this.map = new Map({
        target: targetMap.id,
        view: new View({
          center: this.center,
          maxZoom: 18,
          minZoom: 4,
          zoom: this.zoom,
          constrainResolution:true,//缩放地图可移动到最近的缩放级别（整数zoom级别）
          projection: 'EPSG:4490',
          // resolutions:getResolutions()
        })
      });
      //添加天地图图层
      this.layer1 = getTiandituVecMap();//fxpc天地图街道影像底图
      this.map.addLayer(this.layer1);
      this.layer2 = getTiandituVecText();//fxpc天地图街道地图注记
      this.map.addLayer(this.layer2);
      this.layer1.setZIndex(0);
      this.layer2.setZIndex(0);
      //任务区域图层
      this.taskVectorLayer = new VectorLayer({
        source: new VectorSource({
          wrapX: false
        }),
        projection: 'EPSG:4490'
      });
      this.map.addLayer(this.taskVectorLayer);
      this.taskVectorLayer.setZIndex(1);
      //test
      //let geojsonObject = getFwGeojson();//获取房屋抗争能力分区geojson
      //房屋抗震能力分区图层
      this.fwVectorLayer = new VectorLayer({
        source: new VectorSource({
          //features:new GeoJSON().readFeatures(geojsonObject),
          wrapX: false
        }),
        projection: 'EPSG:4490'
      });
      this.map.addLayer(this.fwVectorLayer);
      this.fwVectorLayer.setZIndex(2);
      //矢量绘制图层
      this.source = new VectorSource({
        wrapX: false
      });
      let vectorLayer = new VectorLayer({
        source: that.source,
        projection: 'EPSG:4490'
      });
      this.map.addLayer(vectorLayer);
      vectorLayer.setZIndex(3);
      //测量结果图层
      this.measureSource = new VectorSource({
        wrapX: false
      });
      let measureLayer = new VectorLayer({
        source: that.measureSource,
        projection: 'EPSG:4490'
      });
      this.map.addLayer(measureLayer);
      measureLayer.setZIndex(3);
      //全部调研点图层
      this.surveyVectorLayer = new VectorLayer({
        source: new VectorSource({
          wrapX: false
        }),
        projection: 'EPSG:4490'
      });
      this.map.addLayer(this.surveyVectorLayer);
      this.surveyVectorLayer.setZIndex(4);
      //添加控件
      let info = new Control({element: document.getElementById(mapStr+'-mapDiv')});
      info.setMap(this.map);
      this.map.addControl(info);
      //弹出窗口
      let popupTarget = document.getElementById(this.str+"-popup");
      if(popupTarget){
        this.popupInfoLayer = new Overlay({
          element: popupTarget,
          positioning: 'center-center'
        });
        this.map.addOverlay(this.popupInfoLayer);
        //显示弹出窗口
        document.getElementById(this.str+"-popup").style.display="block";
        //关闭弹出事件
        document.getElementById(this.str+"-popup-closer").onclick = function () {
          that.popupInfoLayer.setPosition(undefined);
          //隐藏弹出窗口
          document.getElementById(that.str+"-popup").style.display="none";
        };
      }
      //右键菜单--新建调研点
      this.newContextMenu = new Overlay({
        element: document.getElementById(mapStr+"-contextMenuDiv"),
        positioning: 'center-center'
      });
      this.map.addOverlay(this.newContextMenu);
      //显示右键菜单
      document.getElementById(mapStr+"-contextMenuDiv").style.display="block";
      //右键菜单事件
      this.map.on('contextmenu', function(event){
        event.preventDefault();//屏蔽自带的右键事件
        let pixel = that.map.getEventPixel(event.originalEvent);
        let feature = that.map.forEachFeatureAtPixel(pixel,function(feature){
          //根据像素坐标获取右键选中的地图要素
          return feature;
        });
        if(feature && that.draw==null){
          //选中要素
          that.selectFeature = feature;
          let coordinate = that.map.getEventCoordinate(event.originalEvent);
          let geometry = feature.getGeometry();
          //获取多边形区域信息
          if (geometry instanceof Point) {
            let temp = feature.getProperties();
            if(temp.id!=undefined && temp.id!=null){
              //已建调研点
            }else{//新建调研点
              that.surveyAddressData = temp;
              //右键菜单--新建调研点
              that.newContextMenu.setPosition(coordinate);
            }
          }
        }
      });
      //点击地图事件
      this.map.on('click', function(event){
        //隐藏右键菜单
        that.hideContextMenu();
        //隐藏弹出窗口
        if(that.popupInfoLayer!=null){
          that.popupInfoLayer.setPosition(undefined);
        }
        let pixel = that.map.getEventPixel(event.originalEvent);
        let coordinate = that.map.getEventCoordinate(event.originalEvent);
        //判断定位工具是否开启状态
        if(that.showHidePositionTool==false){
          document.getElementById(mapStr+"-MousePositionLon").value = coordinate[0];
          document.getElementById(mapStr+"-MousePositionLat").value = coordinate[1];
        }
        let feature = that.map.forEachFeatureAtPixel(pixel,function(feature){
          //根据像素坐标获取右键选中的地图要素
          return feature;
        });
        if(feature && that.draw==null){
          //选中要素
          that.selectFeature = feature;
          let temp = feature.getProperties();
          console.log("选中要素");
          console.log(feature);
          console.log(temp);
          if(temp.GKZLevel!=undefined && temp.GKZLevel!=null){//房屋抗震能力分区图层
            //设置弹窗内容
            that.setPopupContent(temp);
            that.popupInfoLayer.setPosition(coordinate);
          }else if(temp.id!=undefined && temp.id!=null){//已建调研点
            console.log("查看调研点详情："+temp.id);
            //设置弹窗内容
            that.setPopupContentSurvey(temp);
            that.popupInfoLayer.setPosition(coordinate);
          }
        }
      });
      //地图移动事件
      this.map.on('moveend', function (event) {
        let center = that.map.getView().getCenter();
        let zoom = that.map.getView().getZoom();
        if(center[0]!=that.center[0] || center[1]!=that.center[1] || zoom!=that.zoom){
          //设置主界面图标文字
          that.zoomDefaultPositionBool = false;
        }else{//主界面
          //设置主界面图标文字
          that.zoomDefaultPositionBool = true;
        }
      });
      //鼠标移动事件--测量工具
      this.map.on('pointermove', function (evt) {
        if (evt.dragging) {
          return;
        }
        if(that.measure!=null){
          let helpMsg = '点击开始绘制';

          if (that.sketch) {
            const geom = that.sketch.getGeometry();
            if (geom instanceof Polygon) {
              helpMsg = '点击继续绘制多边形';
            } else if (geom instanceof LineString) {
              helpMsg = '点击继续绘制折线';
            }
          }

          that.helpTooltipElement.innerHTML = helpMsg;
          that.helpTooltip.setPosition(evt.coordinate);

          that.helpTooltipElement.classList.remove('hidden');
        }
      });
      //鼠标移出事件--测量工具
      this.map.getViewport().addEventListener('mouseout', function () {
        if(that.measure!=null){
          that.helpTooltipElement.classList.add('hidden');
        }
      });
      //地址匹配
      this.addressMatchService = new AddressMatchService(this.addressUrl);
      //地图缩放到权限位置
      this.zoomDefaultPosition();
    },
    autodivheight() {//自动获取div高度
      //获取浏览器窗口高度
      let winHeight = 0;
      if (window.innerHeight) {
        winHeight = window.innerHeight;
      } else if ((document.body) && (document.body.clientHeight)) {
        winHeight = document.body.clientHeight;
      }
      //通过深入Document内部对body进行检测，获取浏览器窗口高度
      if (document.documentElement && document.documentElement.clientHeight) {
        winHeight = document.documentElement.clientHeight;
      }
      //全屏时窗口高度:864px,地图div高度:754px
      let tempHeight = 864;
      let mapTempHeight = 754;
      let mapHeight = winHeight - tempHeight + mapTempHeight;
      //最小高度
      if(mapHeight < 525){
        mapHeight = 525;
      }
      //设置地图高度
      document.getElementById(this.str+"-map").style.height= mapHeight +"px";
      console.log("窗口高度："+winHeight+"地图高度："+mapHeight);
      //resize事件--刷新地图,确保地图不变形
      if(this.map){
        this.map.updateSize();
        console.log("resize事件--刷新地图,确保地图不变形");
      }
    },
    setPopupContent(temp){//设置弹窗内容
      let html = "";
      html += "地址："+this.getTextFormat(temp.Province);
      if(!(temp.Province=="北京市" || temp.Province=="天津市" || temp.Province=="上海市" || temp.Province=="重庆市")){
        html += this.getTextFormat(temp.City);
      }
      html += this.getTextFormat(temp.County);
      html += this.getTextFormat(temp.Town);
      html += "<br/>抗震能力："+this.getTextFormat(temp.GKZLevel);
      document.getElementById(this.str+'-popup-content').innerHTML = html;
      //显示弹出窗口
      document.getElementById(this.str+"-popup").style.display="block";
    },
    setPopupContentSurvey(temp){//设置弹窗内容
      let html = "";
      //html += "id："+temp.id;
      html += "调研点名称："+this.getTextFormat(temp.fieldSurveyName);
      let assignorName = this.getTextFormat(temp.assignorName);
      if(assignorName!=""){
        html += "<br/>指定填写人："+assignorName;
      }
      /*html += "<br/>地址："+temp.province;
      if(!(temp.province=="北京市" || temp.province=="天津市" || temp.province=="上海市" || temp.province=="重庆市")){
        html += temp.city;
      }
      html += temp.area;
      html += temp.township;*/
      html += "<br/>地址："+this.getTextFormat(temp.township);
      html += "<br/>经度："+this.getTextFormat(temp.longitude);
      html += "<br/>纬度："+this.getTextFormat(temp.latitude);
      html += "<br/>任务编号："+this.getTextFormat(temp.taskCode);
      html += "<br/>任务名称："+this.getTextFormat(temp.taskName);
      document.getElementById(this.str+'-popup-content').innerHTML = html;
      //显示弹出窗口
      document.getElementById(this.str+"-popup").style.display="block";
    },
    getTextFormat(str){//格式化文本内容
      if(str==null || str==undefined){
        str = "";
      }
      return str;
    },
    hideContextMenu(){//隐藏右键菜单
      //隐藏右键菜单
      this.newContextMenu.setPosition(null);
    },
    //切换地图
    switchMap(){
      if(this.switchMapBool){//显示街道图
        this.switchMapBool = false;
        //添加天地图图层
        if(this.layer1==null){
          this.layer1 = getTiandituVecMap();//fxpc天地图街道影像底图
          this.map.addLayer(this.layer1);
        }
        if(this.layer2==null){
          this.layer2 = getTiandituVecText();//fxpc天地图街道地图注记
          this.map.addLayer(this.layer2);
        }
        //显示街道图
        this.layer1.setVisible(true);
        this.layer2.setVisible(true);
        this.layer3.setVisible(false);
        this.layer4.setVisible(false);
        this.layer1.setZIndex(0);
        this.layer2.setZIndex(0);
      }else{//显示卫星图
        this.switchMapBool = true;
        if(this.layer3==null){
          this.layer3 = getTiandituImgMap();//fxpc天地图卫星影像底图
          this.map.addLayer(this.layer3);
        }
        if(this.layer4==null){
          this.layer4 = getTiandituImgText();//fxpc天地图卫星影像注记
          this.map.addLayer(this.layer4);
        }
        //显示卫星图
        this.layer1.setVisible(false);
        this.layer2.setVisible(false);
        this.layer3.setVisible(true);
        this.layer4.setVisible(true);
        this.layer3.setZIndex(0);
        this.layer4.setZIndex(0);
      }
    },
    //地图缩放到权限位置
    zoomDefaultPosition() {
      //刷新地图,确保地图不变形
      this.map.updateSize();
      this.map.getView().setCenter(this.center);
      this.map.getView().setZoom(this.zoom);
      //设置主界面图标文字
      this.zoomDefaultPositionBool = true;
    },
    //显示工具箱
    showHideToolsBoxDiv(){
      if(this.showHideToolsBox){
        this.showHideToolsBox = false;
        document.getElementById(this.str+"-ToolsBoxDiv").style.display="block";
      }else{
        this.showHideToolsBox = true;
        document.getElementById(this.str+"-ToolsBoxDiv").style.display="none";
      }
      //关闭全部工具
      this.closeAllToolsBox(null);
    },
    //关闭全部工具
    closeAllToolsBox(type){
      //关闭测量工具
      if(type!="MeasureTool" && this.showHideMeasureTool==false){
        this.showHideMeasureTool = true;
        let divId = this.str+"-MeasureToolsDiv";
        //隐藏
        document.getElementById(divId).style.display = "none";
        //清空测量结果
        this.clearMeasure();
        this.clearMeasureBool = true;
      }
      //关闭定位工具
      if(type!="PositionTool" && this.showHidePositionTool==false){
        this.showHidePositionTool = true;
        let divId = this.str+"-MousePositionDiv";
        //隐藏
        document.getElementById(divId).style.display = "none";
        //清空定位结果
        this.clearPosition();
      }
    },
    //地图点选调研点
    mapDrawSurveyPoint(){
      if(this.showHideNewSurveyBool){
        this.showHideNewSurveyBool = false;
        //地图工具箱--地图点选调研点
        this.setMapToolBox('Point');
        document.getElementById(this.str+"-setTaskDiv-span").innerHTML="结束新建";
        document.getElementById(this.str+"-setTaskDiv-img").title="结束新建";
      }else{
        this.showHideNewSurveyBool = true;
        //地图工具箱--结束新建
        this.setMapToolBox('StopDraw');
        document.getElementById(this.str+"-setTaskDiv-span").innerHTML="新建调研点";
        document.getElementById(this.str+"-setTaskDiv-img").title="新建调研点";
      }
    },
    //新建调研点
    newSurveyData(){
      let temp = this.surveyAddressData;
      this.$emit("newSurveyData",temp);
      //隐藏右键菜单
      this.hideContextMenu();
    },
    mapLoading(msg){//地图查询Loading
      this.$emit("mapLoading",msg);
    },
    measureToolBox(){//测量工具Div
      let divId = this.str+"-MeasureToolsDiv";
      //关闭全部工具
      this.closeAllToolsBox("MeasureTool");
      if(this.showHideMeasureTool){
        this.showHideMeasureTool = false;
        //显示
        document.getElementById(divId).style.display = "block";
      }else{
        this.showHideMeasureTool = true;
        //隐藏
        document.getElementById(divId).style.display = "none";
      }
    },
    measureDistance(){//测距
      if(this.source!=null){
        //地图工具箱--开启测距
        this.setMapToolBox('MeasureDistance');
        //设置样式
        this.measureDistanceBool = false;
        this.measureAreaBool = true;
        this.stopMeasureBool = true;
        this.clearMeasureBool = true;
      }
    },
    measureArea(){//测面
      if(this.source!=null){
        //地图工具箱--开启测面
        this.setMapToolBox('MeasureArea');
        //设置样式
        this.measureAreaBool = false;
        this.measureDistanceBool = true;
        this.stopMeasureBool = true;
        this.clearMeasureBool = true;
      }
    },
    stopMeasure(){//停止测量
      if(this.source!=null){
        //地图工具箱--停止测量
        this.setMapToolBox('StopMeasure');
        //设置样式
        this.stopMeasureBool = false;
        this.measureDistanceBool = true;
        this.measureAreaBool = true;
        this.clearMeasureBool = true;
      }
    },
    clearMeasure(){//清空测量结果
      if(this.source!=null){
        //地图工具箱--清空测量结果
        this.setMapToolBox('ClearMeasure');
        //设置样式
        this.clearMeasureBool = false;
        this.measureDistanceBool = true;
        this.measureAreaBool = true;
        this.stopMeasureBool = true;
      }
    },
    positionToolBox(){//定位工具Div
      let divId = this.str+"-MousePositionDiv";
      //关闭全部工具
      this.closeAllToolsBox("PositionTool");
      if(this.showHidePositionTool){
        this.showHidePositionTool = false;
        //显示
        document.getElementById(divId).style.display = "block";
      }else{
        this.showHidePositionTool = true;
        //隐藏
        document.getElementById(divId).style.display = "none";
      }
    },
    addPosition(){//添加定位结果
      this.clearPositionBool = true;
      this.addPositionBool = false;
      //添加定位结果
      if(this.source!=null){
        let longitude = document.getElementById(this.str+"-MousePositionLon").value;
        let latitude = document.getElementById(this.str+"-MousePositionLat").value;
        //处理经纬度
        let lonlat = this.getLonLat(longitude,latitude);
        if(lonlat!=null){
          //点
          let featureTmp = new Feature({
            geometry: new Point(lonlat)
          });
          //样式
          let style = this.getPointStyle();
          featureTmp.setStyle(style);
          //设置属性
          featureTmp.setProperties({
            type:"position",
            longitude:longitude,
            latitude:latitude,
          });
          //添加定位点
          this.source.addFeature(featureTmp);
          //居中缩放
          this.map.getView().setCenter(lonlat);
          this.map.getView().setZoom(12);
        }
      }
    },
    clearPosition(){//清空定位结果
      this.clearPositionBool = false;
      this.addPositionBool = true;
      //地图工具箱--清空
      this.setMapToolBox("Clear");
    },
    //地图工具箱
    setMapToolBox(value){
      let that = this;
      if (value === 'Clear') {//清空
        //清空
        that.source.clear();
        //停止绘制|修改|拖拽|选择
        clearInteraction();
      }else if (value === 'Point' || value === 'LineString' || value === 'Polygon' || value === 'Circle') {//开启绘制
        //点|线|面|圆绘制
        //开启绘制
        startDrawInteraction(value,false);
      }else if (value === 'FreeHandLineString' || value === 'FreeHandPolygon') {//开启绘制
        //手绘线|手绘面
        value = value.split("FreeHand")[1];
        //开启绘制
        startDrawInteraction(value,true);
      }else if (value === 'StopDraw') {//停止绘制
        //停止绘制
        stopDrawInteraction();
      }else if (value === 'Snap') {//开启捕捉
        //开启捕捉
        startSnapInteraction();
      }else if (value === 'NotSnap') {//停止捕捉
        //停止捕捉
        stopSnapInteraction();
      }else if (value === 'Modify') {//开启修改
        //开启修改
        startModifyInteraction();
      }else if (value === 'NotModify') {//停止修改
        //停止修改
        stopModifyInteraction();
        //停止选择
        stopSelectInteraction();
      }else if (value === 'Drag') {//开启拖拽
        //开启拖拽
        startDragInteraction();
      }else if (value === 'NotDrag') {//停止拖拽
        //停止拖拽
        stopDragInteraction();
      } else if (value === 'Select') {//开启选择
        //开启选择
        startSelectInteraction();
      } else if (value === 'NotSelect') {//停止选择
        //停止选择
        stopSelectInteraction();
      } else if (value === 'MeasureDistance') {//开启测距
        //开启测距
        startMeasureInteraction('LineString');
      } else if (value === 'MeasureArea') {//开启测面
        //开启测面
        startMeasureInteraction('Polygon');
      } else if (value === 'StopMeasure') {//停止测量（测距|测面）
        //停止测量
        stopMeasureInteraction();
      } else if (value === 'ClearMeasure') {//清空测量结果
        //停止测量
        stopMeasureInteraction();
        //清空测量结果
        clearMeasureResult();
      }

      //停止绘制|修改|拖拽|选择
      function clearInteraction() {
        //停止拖拽
        stopDragInteraction();
        //停止修改
        stopModifyInteraction();
        //停止选择
        stopSelectInteraction();
        //停止绘制
        stopDrawInteraction();
      }

      //停止捕捉
      function stopSnapInteraction(){
        if (that.snap) {
          that.map.removeInteraction(that.snap);
          that.snap = null;
        }
      }

      //开启捕捉
      function startSnapInteraction(){
        //停止捕捉
        stopSnapInteraction();
        //开启捕捉
        that.snap = new Snap({
          source: that.source
        });
        that.map.addInteraction(that.snap);
      }

      //停止拖拽
      function stopDragInteraction() {
        //停止拖拽
        if (that.drag) {
          that.map.removeInteraction(that.drag);
          that.drag = null;
        }
      }

      //开启拖拽
      function startDragInteraction() {
        //停止绘制
        stopDrawInteraction();
        //停止修改
        stopModifyInteraction();
        //开启选择
        startSelectInteraction();
        //停止拖拽
        stopDragInteraction();
        //开启拖拽
        that.drag = new Translate({
          features: that.select.getFeatures()
        });
        that.map.addInteraction(that.drag);
      }

      //停止修改
      function stopModifyInteraction() {
        //停止修改
        if (that.modify) {
          that.map.removeInteraction(that.modify);
          that.modify = null;
        }
      }

      //开启修改
      function startModifyInteraction() {
        //停止绘制
        stopDrawInteraction();
        //开启选择
        startSelectInteraction();
        //停止修改
        stopModifyInteraction();
        //开启修改
        that.modify = new Modify({
          features: that.select.getFeatures()
        });
        that.map.addInteraction(that.modify);
      }

      //停止选择
      function stopSelectInteraction() {
        //停止选择
        if (that.select) {
          that.map.removeInteraction(that.select);
          that.select = null;
        }
      }

      //开启选择
      function startSelectInteraction() {
        //停止选择
        stopSelectInteraction();
        //开启选择
        that.select = new Select({
          wrapX: false
        });
        that.map.addInteraction(that.select);
      }

      //停止绘制
      function stopDrawInteraction() {
        //停止绘制
        if (that.draw) {
          that.map.removeInteraction(that.draw);
          that.draw = null;
        }
      }

      //开启绘制
      function startDrawInteraction(type,bool) {
        //停止拖拽
        stopDragInteraction();
        //停止修改
        stopModifyInteraction();
        //停止选择
        stopSelectInteraction();
        //停止绘制
        stopDrawInteraction();
        if(bool){//手绘线|手绘面
          that.draw = new Draw({
            source: that.source,
            type: type,
            snapTolerance: 20,
            freehand: true
          });
          that.map.addInteraction(that.draw);
        }else{//点|线|面|圆绘制
          that.draw = new Draw({
            source: that.source,
            type: type,
            snapTolerance: 20
          });
          that.map.addInteraction(that.draw);
          //绘制结束时触发的事件
          that.draw.on('drawend', function(e) {
            const geometry = e.feature.getGeometry();
            let pointArr = geometry.getCoordinates();
            //停止绘制
            stopDrawInteraction();
            console.log("点图标");
            //点图标
            if (geometry instanceof Point) {
              if(that.taskRegionData!=null && that.taskRegionData!=""){//任务区域经纬度数据
                //判断点是否在面内
                let bool = that.judgePointInPolygon(geometry);
                if(bool){
                  //设置样式
                  let style = that.getPointTempStyle();//新建点图标样式
                  e.feature.setStyle(style);
                  console.log(pointArr);
                  let lon = pointArr[0];
                  let lat = pointArr[1];
                  //正在查询
                  that.mapLoading("正在查询，请稍候...");
                  //经纬度地址解析
                  that.getAddress(e.feature,lon,lat);
                }else{
                  //that.$message({ message: '恭喜你，这是一条成功消息', type: 'success' });
                  that.$message({ message: '请在任务区域内选点!', type: 'warning' });
                  //that.$confirm('此操作将永久删除该文件, 是否继续?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { that.$message({ type: 'success', message: '删除成功!' }); }).catch(() => { that.$message({ type: 'info', message: '已取消删除' }); });
                  //清空点图标
                  setTimeout(function(){
                    that.source.removeFeature(e.feature);
                  },100);
                }
              }
              //结束地图点选调研点
              that.mapDrawSurveyPoint();
            }
          });
        }
      }

      //计算面积
      function getPolygonArea (polygon) {
        // 这里一定要给坐标，和地图坐标保持一致，否则面积不准
        const area = getArea(polygon, {projection: 'EPSG:4490'})
        let output;
        /*if (area > 10000) {
          output = Math.round((area / 1000000) * 100) / 100 + ' ' + 'km<sup>2</sup>';
        } else {
          output = Math.round(area * 100) / 100 + ' ' + 'm<sup>2</sup>';
        }*/
        output = Math.round((area / 1000000) * 100) / 100;//平方公里
        return output;
      }

      ////////////////////////////////////////////////////////////////////测量工具箱
      //格式化距离
      function formatLength(line) {
        const length = getLength(line, {projection: 'EPSG:4490'});
        let output;
        if (length > 100) {
          output = Math.round((length / 1000) * 100) / 100 + ' ' + 'km';
        } else {
          output = Math.round(length * 100) / 100 + ' ' + 'm';
        }
        return output;
      }

      //格式化面积
      function formatArea(polygon) {
        const area = getArea(polygon, {projection: 'EPSG:4490'});
        let output;
        if (area > 10000) {
          output = Math.round((area / 1000000) * 100) / 100 + ' ' + 'km<sup>2</sup>';
        } else {
          output = Math.round(area * 100) / 100 + ' ' + 'm<sup>2</sup>';
        }
        return output;
      }

      //创建新的提示tip
      function createHelpTooltip() {
        if (that.helpTooltipElement!=null) {
          that.helpTooltipElement.parentNode.removeChild(that.helpTooltipElement);
        }
        that.helpTooltipElement = document.createElement('div');
        that.helpTooltipElement.className = 'ol-tooltip hidden';
        that.helpTooltip = new Overlay({
          element: that.helpTooltipElement,
          offset: [15, 0],
          positioning: 'center-left',
        });
        that.map.addOverlay(that.helpTooltip);
      }

      //创建新的测量提示
      function createMeasureTooltip() {
        if (that.measureTooltipElement!=null) {
          that.measureTooltipElement.parentNode.removeChild(that.measureTooltipElement);
        }
        that.measureTooltipElement = document.createElement('div');
        that.measureTooltipElement.className = 'ol-tooltip ol-tooltip-measure';
        that.measureTooltip = new Overlay({
          element: that.measureTooltipElement,
          offset: [0, -15],
          positioning: 'bottom-center',
          stopEvent: false,
          insertFirst: false,
        });
        that.map.addOverlay(that.measureTooltip);
      }

      //开启测量工具
      function startMeasureInteraction(type) {
        //停止测量工具
        stopMeasureInteraction();

        console.log(type);
        //开启测量工具--绘制
        that.measure = new Draw({
          source: that.measureSource,
          type: type,
          style: new Style({
            fill: new Fill({
              color: 'rgba(255, 255, 255, 0.2)',
            }),
            stroke: new Stroke({
              color: 'rgba(0, 0, 0, 0.5)',
              lineDash: [10, 10],
              width: 2,
            }),
            image: new Circle({
              radius: 5,
              stroke: new Stroke({
                color: 'rgba(0, 0, 0, 0.7)',
              }),
              fill: new Fill({
                color: 'rgba(255, 255, 255, 0.2)',
              }),
            }),
          }),
        });
        that.map.addInteraction(that.measure);

        //创建新的测量提示
        createMeasureTooltip();
        //创建新的提示tip
        createHelpTooltip();

        let listener;
        that.measure.on('drawstart', function (evt) {
          //设置sketch
          that.sketch = evt.feature;

          let tooltipCoord = evt.coordinate;

          listener = that.sketch.getGeometry().on('change', function (evt) {
            const geom = evt.target;
            let output;
            if (geom instanceof Polygon) {
              output = formatArea(geom);
              tooltipCoord = geom.getInteriorPoint().getCoordinates();
            } else if (geom instanceof LineString) {
              output = formatLength(geom);
              tooltipCoord = geom.getLastCoordinate();
            }
            that.measureTooltipElement.innerHTML = output;
            that.measureTooltip.setPosition(tooltipCoord);
          });
        });
        //完成测量绘制
        that.measure.on('drawend', function () {
          that.measureTooltipElement.className = 'ol-tooltip ol-tooltip-static';
          that.measureTooltip.setOffset([0, -7]);
          //添加到数组
          that.measureTooltipArray.push(that.helpTooltip);
          //添加到数组
          that.measureTooltipArray.push(that.measureTooltip);
          //清空sketch
          that.sketch = null;
          //清空tooltip
          that.measureTooltipElement = null;
          createMeasureTooltip();
          unByKey(listener);
        });
      }

      //停止测量工具
      function stopMeasureInteraction() {
        //停止绘制
        stopDrawInteraction();
        //停止测量工具
        if (that.measure) {
          that.map.removeInteraction(that.measure);
          that.measure = null;
          //隐藏提示tip
          that.helpTooltipElement.classList.add('hidden');
          //移除测量提示
          if(that.helpTooltip!=null){
            that.map.removeOverlay(that.helpTooltip);
          }
          if(that.measureTooltip!=null){
            that.map.removeOverlay(that.measureTooltip);
          }
        }
      }

      //清空测量结果
      function clearMeasureResult(){
        if(that.measureSource!=null){
          //清空测量结果
          that.measureSource.clear();
          //清空测量结果提示数组
          if(that.measureTooltipArray.length>0){
            for(let i=0;i<that.measureTooltipArray.length;i++){
              that.map.removeOverlay(that.measureTooltipArray[i]);
            }
            that.measureTooltipArray = [];
          }
        }
      }
    },
    getPolyonStyle(color){//多边形样式
      let style = new Style({
        fill:new Fill({//填充样式
          color:"rgba(0,0,0,0)"
        }),
        stroke:new Stroke({//描绘
          width:2,//宽
          color:color
        })
      });

      return style;
    },
    getPointStyle(){//点图标样式
      let style = new Style({
        image: new Icon({
          src: dingweiImg,
          anchor: [0.5, 1]
        }),
      });

      return style;
    },
    getPointTempStyle(){//新建点图标样式
      let style = new Style({
        image: new Icon({
          src: dingweiTempImg,
          anchor: [0.5, 1]
        }),
      });

      return style;
    },
    getAddress(feature,lon,lat){//经纬度地址解析
      let that = this;
      /*//反向匹配参数
      let geoDecodeParam = new GeoDecodingParameter({
        x: lon, // 横坐标
        y: lat, // 纵坐标
        fromIndex: 0, // 最小索引
        toIndex: 1, // 最大索引
        filters: "北京市", // 过滤字段
        prjCoordSys: '{epsgcode:4490}', // 坐标设置
        maxReturn: 1, // 最大结果数
        geoDecodingRadius: 1000 // 查询半径
      });
      // 创建地址匹配服务
      let addressUrl = "https://iserver.supermap.io/iserver/services/addressmatch-Address/restjsr/v1/address";
      let addressMatchService = new AddressMatchService(addressUrl);
      // 向服务端发送请求进行反向地址匹配，并对返回的结果进行处理
      addressMatchService.decode(geoDecodeParam,function(obj){
          // 获取服务端返回的结果
          let featuers = obj.result;
          console.log(featuers);
          alert(featuers);
      });*/
      let url = "https://fxpc.mem.gov.cn/data_preparation/171dd1d5-bbb3-483a-a7f6-50d6d98cee1f/b5c55956-d1d7-4c00-8ccc-3145269327e3/reverse_geocoding?location=" + lon + "," +lat + "&geokey=94E99EB4FEB9B48CD5348F7BCF5BB620";
      /*let url = 'http://api.tianditu.gov.cn/geocoder?postStr={\'lon\':' +
          lon +
          ',\'lat\':' +
          lat +
          ',\'ver\':1}&type=geocode&tk=aeb17a8215786a5dd17f5f9c92bebc0c';*/
      //天地图数据服务获取地址--逆地理编码查询
      let httpRequest = new XMLHttpRequest();//第一步：建立所需的对象
      httpRequest.open('GET', url, true);//第二步：打开连接  将请求参数写在url中  ps:"http://localhost:8080/rest/xxx"
      httpRequest.send();//第三步：发送请求  将请求参数写在URL中
      /**
       * 获取数据后的处理程序
       */
      httpRequest.onreadystatechange = function () {
        if (httpRequest.readyState == 4 && httpRequest.status == 200) {
          let json = httpRequest.responseText;//获取到json字符串，还需解析
          let obj = JSON.parse(json);
          console.log("地址解析");
          console.log(obj);
          //let addressComponent = obj.result.addressComponent;
          let addressComponent = obj.result.address_component;
          console.log(addressComponent);
          let province = addressComponent.province;
          let city = addressComponent.city;
          let area = addressComponent.district;
          let township = obj.result.formatted_address;
          if(obj.status=="0"){
            //设置属性
            feature.setProperties({
              longitude:that.numberAround(lon,8),
              latitude:that.numberAround(lat,8),
              province:province,
              city:city,
              //area:addressComponent.county,
              area:area,
              township:township
            });
            console.log(obj.result.formatted_address);
          }else{
            console.log("error");
            that.$message({ message: '请在任务区域内选点!', type: 'warning' });
            //清空点图标
            setTimeout(function(){
              that.source.removeFeature(feature);
            },100);
          }
        }
        //完成查询
        that.mapLoading(null);
      };
    },
    numberAround(number,len){
      // 四舍五入保留len位小数
      return number.toFixed(len);
    },
    drawTaskPolygon(){//绘制任务区域
      let taskRegion = this.taskRegionData;
      if(taskRegion!=null && taskRegion!="" && this.taskVectorLayer!=null){
        this.taskVectorLayer.getSource().clear();//清空区域
        if(taskRegion.indexOf("MULTIPOLYGON")==-1) {//地图绘制区域
          console.log("地图绘制区域");
          let coordinates = [];
          let arr = taskRegion.split(";");
          if(arr!=null && arr.length>0){
            for(let j=0;j<arr.length;j++){
              let lonlatStr = arr[j].split(",");
              let lonlat = [];
              lonlat.push(Number(lonlatStr[0]));
              lonlat.push(Number(lonlatStr[1]));
              coordinates.push(lonlat);
            }
          }
          console.log(coordinates);
          //多边形
          let featureTmp = new Feature({
            geometry: new Polygon([coordinates])
          });
          //样式
          let style = this.getPolyonStyle("orange");
          featureTmp.setStyle(style);
          //添加任务区域
          this.taskVectorLayer.getSource().addFeature(featureTmp);
          //缩放到区域位置
          this.showBoundingExtent(coordinates);
        }else{//行政区划选择区域
          console.log("行政区划选择区域");
          let allCoordinates = [];
          let all_coords_str = taskRegion.split(";");
          for(let i=0;i<all_coords_str.length;i++){
            let coords_str = all_coords_str[i].split("MULTIPOLYGON (((")[1].split(")))")[0];
            if(coords_str.indexOf(")), ((")!=-1){
              console.log("多个的面");
            }
            let geometries = coords_str.split(")), ((");
            console.log("geometries: ", geometries.length);
            for (let k = 0;k < geometries.length;k++) {
              //console.log(geometries[k]);
              let allPointsArr = [];
              if(coords_str.indexOf("), (")!=-1){
                console.log("镂空的面");
              }
              let __coords = geometries[k].split("), (");
              console.log("__coords: ", __coords.length);
              for (let m = 0;m < __coords.length;m++) {
                let _coords = __coords[m].split(", "), points = [];
                //console.log(_coords);
                for (let n = 0;n < _coords.length;n++) {
                  if(_coords[n]!=null && _coords[n]!=""){
                    let coord = _coords[n].split(" ");
                    let lon = Number(coord[0]), lat = Number(coord[1]);
                    let lonlat = [lon, lat];
                    points.push(lonlat);
                    allCoordinates.push(lonlat);
                  }
                }
                allPointsArr.push(points);
              }
              console.log(i+"--allPointsArr:");
              console.log(allPointsArr);
              //多边形
              let featureTmp = new Feature({
                geometry: new Polygon(allPointsArr)
              });
              //样式
              let style = this.getPolyonStyle("orange");
              featureTmp.setStyle(style);
              //添加任务区域
              this.taskVectorLayer.getSource().addFeature(featureTmp);
            }
          }
          //缩放到区域位置
          this.showBoundingExtent(allCoordinates);
        }
      }
    },
    judgePointInPolygon(point){//判断点是否在面内
      let bool = false;
      let coor = point.getCoordinates();
      let features = this.taskVectorLayer.getSource().getFeatures();
      if(features!=null && features.length>0){
        for(let i=0;i<features.length;i++){
          let feature = features[i];
          let polygon = feature.getGeometry();
          bool = polygon.intersectsCoordinate(coor);
          if(bool){
            break;
          }
        }
      }
      return bool;
    },
    showHideFwLayer(){//显示隐藏房屋抗震能力分区图层
      if(this.fwVectorLayer!=null){
        if(this.showHideFwLayerBool){
          this.showHideFwLayerBool = false;
          this.fwVectorLayer.getSource().clear();
          //test
          let geojsonObject = getFwGeojson();//获取房屋抗震能力分区geojson
          //获取数据
          let features = new GeoJSON().readFeatures(geojsonObject);
          //添加房屋抗震能力分区图层
          this.fwVectorLayer.getSource().addFeatures(features);
          //设置样式
          if(features.length>0){
            for(let i=0;i<features.length;i++){
              let temp = features[i].getProperties();
              let level = temp.GKZLevel;
              if(level!=undefined && level!=null){
                //根据房屋抗震能力级别获取颜色
                let index = this.isObjInArray(this.fwLayerTypeList,level);
                if(index!=-1){
                  let color = this.fwLayerColorList[index];
                  //样式
                  let style = this.getPolyonStyle(color);
                  features[i].setStyle(style);
                }
              }
            }
          }
        }else{
          this.showHideFwLayerBool = true;
          //清空图层
          this.fwVectorLayer.getSource().clear();
        }
      }
    },
    isObjInArray(array,obj){//判断数组中是否包含对象
      let index = -1;
      if(array!=null && array.length>0){
        for(let i=0;i<array.length;i++){
          if(obj==array[i]){
            index = i;
            break;
          }
        }
      }
      return index;
    },
    //处理经纬度
    getLonLat(longitude,latitude){
      let lonlat = null;
      if(longitude!=null && latitude!=null && longitude!="" && latitude!=""){
        let lon = Number(longitude);
        let lat = Number(latitude);
        if(lon>0 && lon<180 && lat>0 && lat<90){
          lonlat = [lon,lat];
        }
      }

      return lonlat;
    },
    showAllDataList(){//显示查询数据列表
      console.log("显示查询数据列表");
      if(this.surveyVectorLayer!=null){
        this.surveyVectorLayer.getSource().clear();//清空
        let newVal = this.allDataList;
        console.log(newVal);
        if(newVal.length>0){
          for(let i=0;i<newVal.length;i++){
            let longitude = newVal[i].longitude;
            let latitude = newVal[i].latitude;
            //处理经纬度
            let lonlat = this.getLonLat(longitude,latitude)
            if(lonlat!=null){
              //点
              let featureTmp = new Feature({
                geometry: new Point(lonlat)
              });
              //样式
              let style = this.getPointStyle();
              featureTmp.setStyle(style);
              //设置属性
              featureTmp.setProperties({
                id:newVal[i].id,
                taskCode:newVal[i].taskCode,
                taskName:newVal[i].taskName,
                province:newVal[i].province,
                city:newVal[i].city,
                area:newVal[i].area,
                township:newVal[i].township,
                assignorName:newVal[i].assignorName,
                fieldSurveyName:newVal[i].fieldSurveyName,
                longitude:newVal[i].longitude,
                latitude:newVal[i].latitude,
              });
              //添加查询数据列表
              this.surveyVectorLayer.getSource().addFeature(featureTmp);
            }
          }
        }
      }
    },
    showBoundingExtent(coordinates){//缩放到区域位置
      console.log("缩放到区域位置");
      if (coordinates!=null && coordinates.length > 1) {
        const extent = boundingExtent(coordinates);
        //this.map.getView().fit(extent, {duration: 1000, padding: [50, 50, 50, 50]});
        this.map.getView().fit(extent, {padding: [50, 50, 50, 50]});
        //获取默认位置
        this.center = this.map.getView().getCenter();
        this.zoom = this.map.getView().getZoom();
      }
    }
  }
}

</script>

<style scoped>

</style>